package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.model.dto.correlation.CorrelationDTO;
import com.vhans.db.model.vo.correlation.PurchasedInfo;
import com.vhans.db.service.CorrelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关联表Controller控制器
 *
 * @author vhans
 * @date 2023-05-20
 */
@Api(tags = "关联表模块")
@RestController
@RequestMapping("/dome/correlation")
public class CorrelationController extends BaseController {

    @Autowired
    private CorrelationService correlationService;

    /**
     * 新增关联id
     *
     * @param correlationDTO 关联id信息
     * @return {@link Result <>}
     */
    @ApiOperation(value = "新增基本属性")
    @SaCheckPermission("dome:correlation:add")
    @PostMapping("/add")
    public Result<?> add(@Validated @RequestBody CorrelationDTO correlationDTO) {
        return toAjax(correlationService.insertCorrelation(correlationDTO));
    }

    /**
     * 获取已购买的产品信息
     *
     * @return {@link Result<List<PurchasedInfo>>}
     */
    @ApiOperation(value = "获取已购买的产品信息")
    @SaCheckPermission("dome:correlation:get")
    @GetMapping("/getInfo")
    public Result<List<PurchasedInfo>> getPurchasedInfo() {
        return Result.success(correlationService.getPurchasedInfo());
    }
}
